﻿using DeHeng_Mes.Model;
using DeHeng_Mes.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using W03_UI.Table;

namespace DeHeng_Mes.Dao
{
    class QueryDataDao
    {
        public List<TraceFDS> GetFDSDtlData(string code)
        {
            using (var db = MySqlSugarConfig.Db)
            {
                return db.Queryable<TraceFDS>()
                         .Where(x => x.ScrewID == code)
                         .Select(x => new TraceFDS
                         {
                             ScrewID = x.ScrewID.ToString(),
                             OK_NOK_Code = x.OK_NOK_Code.ToString(),
                             SystemId = x.SystemId.ToString(),
                             StartTime = x.StartTime.ToString(),
                             AutoIndex = x.AutoIndex.ToString(),
                         })
                         .ToList();
            }
        }

        /// <summary>
        /// 查询步序结果
        /// </summary>
        /// <param name="autoIndex"></param>
        /// <returns></returns>
        public List<TraceFdsStep> GetFdsStep(List<long> autoIndex)
        {
            using (var db = MySqlSugarConfig.Db)
            {
                return db.Queryable<TraceFdsStep>()
                         .Where(x => autoIndex.Contains(x.AutoProgIndex))
                         .Select(x => new TraceFdsStep
                         {
                             AutoProgIndex = x.AutoProgIndex,
                             Name = x.Name.ToString(),
                             Parameter = x.Parameter.ToString(),
                             StepIndex = x.StepIndex.ToString(),
                             IoNio = x.IoNio.ToString(),
                         })
                         .ToList();
            }
        }

        /// <summary>
        /// 查找FDS配置参数表
        /// </summary>
        /// <param name="autoIndex"></param>
        /// <returns></returns>
        public List<TraceFDSDtl> GetFdsDtl(List<long> autoIndex)
        {
            using (var db = MySqlSugarConfig.Db)
            {
                return db.Queryable<TraceFDSDtl>()
                         .Where(x => autoIndex.Contains(x.AutoProgIndex))
                         .Select(x => new TraceFDSDtl
                         {
                             AutoProgIndex = x.AutoProgIndex,
                             Name = x.Name.ToString(),
                             StepIndex = x.StepIndex.ToString(),
                             Parameter = x.Parameter,
                         })
                         .ToList();
            }
        }
    }
}
